/**
 * 删除功能
 */

function deletePolicy(obj) {
    // 获取当前行
    var row = obj.parentNode.parentNode;
    // 获取当前行中的所有单元格
    tds = row.getElementsByTagName('td');
    
    var msg = "请确认是否删除策略！";
    if (confirm(msg)==true){
        var deleteInfo = tds[0].innerText + ","
            + tds[1].innerText + ","
            + tds[2].innerText + ","
            + tds[3].innerText;
        // console.log(deleteInfo);
        // 发送请求
        $.ajax({
            url: "http://127.0.0.1:8023/abac/policy/info",
            type: "PUT",
            dataType: "JSON",
            contentType: "application/x-www-form-urlencoded",
            // async:false,
            data: {
                pType: "P",
                policy: deleteInfo
            },
            success: function(res) {
                // 重新获取表格数据
                getData();
                // load();
                // 获取当前页码
                var currentPage = document.getElementById('currentPage').innerText;
                var totalPages = Math.ceil(data.length / 10);
                if (currentPage > totalPages) {
                    // 如果当前页码值大于总页码，跳回到上一页
                    pre();
                } else {
                    // 重新渲染当前页数据
                    showData(document.getElementById('currentPage').innerText);
                }
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                alert("删除失败！");
            }
        });
        return true;
    }else{
        return false;
    }
}